/*
 * @Description: promise.allSettled使用
 * @Author: Zhanghan
 * @Date: 2025-03-24 09:32:09
 * @LastEditTime: 2025-03-24 09:55:59
 * @LastEditors: Zhanghan
 */
import { Button } from "antd";
function AllSettled() {
  const handleAllSettled = async () => {
    const promise1 = Promise.resolve(3);
    const promise2 = new Promise((resolve, reject) =>
      setTimeout(() => reject("失败了"), 4000)
    );

    const promises = [promise1, promise2];

    const results = await Promise.allSettled(promises);
    results.forEach((result) => console.log(result));
  };

  return (
    <>
      <div className="mb-2">
        <div> promise.allSettled使用</div>
        静态方法将一个 Promise 可迭代对象作为输入，并返回一个单独的
        Promise。当所有输入的 Promise
        都已敲定时（包括传入空的可迭代对象时），返回的 Promise
        将被兑现，并带有描述每个 Promise 结果的对象数组。
      </div>
      <div className="flex items-center">
        <Button type="primary" onClick={handleAllSettled}>
          点击执行
        </Button>
      </div>
    </>
  );
}

export default AllSettled;
